﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CORRECTASKANSWER.aspx.cs" Inherits="Teacher_CORRECTASKANSWER" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>

    <script src="../layui/layui.js"></script>
    <script src="../JS/jquery-3.3.1.min.js"></script>
    <link href="../layui/css/layui.css" rel="stylesheet" />
    <script type="text/html" id="tableBarTool">
        <a class="layui-btn layui-btn-xs" lay-event="download">下载用户文件</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="save">保存</a>
    </script>


</head>
<body>
    <script>
        layui.use(['table', 'layer'], function () {
            var table = layui.table;
            var layer = layui.layer;
            

            //第一个实例
            table.render({
                elem: '#CorrectAA'
                , height: 600
                , url: '/handler/EMSsystem.ashx?Action=CorrectAA&Method=GetTable&USERID='+'<%=Session["ID"] %>' //数据接口
                , page: true //开启分页
                , cols: [[ //表头
                     { type: 'radio',title:'选择' }
                    , { field: 'ID', title: 'ID', hide: true }
                    , { field: 'PaperID', title: '试卷ID', hide: true }
                    , { field: 'PaperName', title: '试卷', width: 100 }
                    , { field: 'TITLEID', title: '题目ID', hide: true }
                    , { field: 'UserID', title: '用户ID', hide: true }
                    , { field: 'USER_NAME', title: '用户名称', width: 100 }
                    , { field: 'TITLE', title: '题目', width: 800 }
                    , { field: 'USERANSWER', title: '用户上传文件', hide: true }
                    , { field: 'Mark', title: '该题分值', width: 100 }
                    , { field: 'USERMARK', title: '用户得分（点击编辑）', align: 'center', width: 200, edit: 'text' }
                    , { fixed: 'right', title: '操作', align: 'center', toolbar: '#tableBarTool' }
                ]]
            });

            table.on('tool(CorrectAA)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
                var data = obj.data //获得当前行数据
                    , layEvent = obj.event; //获得 lay-event 对应的值
                if (layEvent === 'download') {
                    var type = (data.USERANSWER).split(".");
                    if (type[1] === "txt") {
                        var a = $('<a></a>');
                        a.attr('href', data.USERANSWER);
                        a.prop('download', data.USERANSWER.split("_")[1]);
                        a.get(0).click();
                    }

                    else {
                        var $form = $('<form method="GET"></form>');
                        $form.attr('action', data.USERANSWER);
                        $form.appendTo($('body'));
                        $form.submit();
                    }
                } else if (layEvent === 'save') {

                    var patrn = /^(-)?\d+(\.\d+)?$/;
                    if (patrn.exec(data.USERMARK) == null || data.USERMARK == "") {
                        layer.msg("请输入正确的数字！");
                        return;
                    }

                    if (Number(data.Mark) < Number(data.USERMARK)) {

                        layer.msg("该题得分不得超过" + data.Mark + "分");
                        return;
                    }

                    $.ajax({
                        type: "post",
                        url: '/handler/EMSsystem.ashx?Action=CorrectAA&Method=SaveData', //数据接口
                        data: { "ID": data.ID, "USERMARK": data.USERMARK, "UserID": data.UserID, "PaperID": data.PaperID },
                        success: function (obj) {
                            if (obj) {
                                var back = eval('(' + obj + ')');
                                var msg = back.msg;
                                layer.msg(msg);
                            }
                        }
                    })

                }
            });


        });
    </script>

    <table id="CorrectAA" lay-filter="CorrectAA"></table>

    <form id="form1" runat="server">
    </form>
</body>
</html>
